package com.bdqn.business.student.controller;

import com.bdqn.aop.Log;
import com.bdqn.business.student.service.StudentExamService;
import com.bdqn.entity.academic.Exam;
import com.bdqn.error.CommonException;
import com.bdqn.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.Map;

@RestController
@RequestMapping("/student/exam")
public class StudentExamController {

    @Autowired
    private StudentExamService studentExamService;

    @Log("学生端:试卷列表")
    @RequestMapping(value = "/getList",method = RequestMethod.POST)
    public Result getList(@RequestBody Map<String,Object> map){
        return studentExamService.getList(map);
    }

    //当学生点击开始考试按钮时,查看学生的试卷是否是2,如果是2,则不让再次进入考试
    @Log("学生端:点击考试时校验是否是2")
    @RequestMapping(value = "/getScoreStatus/{id}",method = RequestMethod.GET)
    public Result getScoreStatus(@PathVariable("id") String id) throws CommonException {
        return studentExamService.getScoreStatus(id);
    }

    @Log("学生端:从redis中获得试卷信息")
    @RequestMapping(value = "/findExamByRedis/{id}",method = RequestMethod.POST)
    public Result findExamByRedis(@PathVariable("id")String id){
        return studentExamService.findExamByRedis(id);
    }

    @Log("学生端:保存学生答卷时的临时答案")
    @RequestMapping(value = "/saveTempDataToRedis",method = RequestMethod.POST)
    public Result saveTempDataToRedis(@RequestBody Map<String,Object> map){
        return studentExamService.saveTempDataToRedis(map);
    }

    @Log("学生端：上传机试题")
    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public Result uploadStudentUpper(@RequestParam("file") MultipartFile file,@RequestParam Map<String,Object> map) throws IOException {
        return studentExamService.uploadStudentUpper(file,map);
    }

    @Log("学生端：校验当前学生的当前试卷是否已经上传上机题")
    @RequestMapping(value = "/checkUpperResult/{examId}",method = RequestMethod.GET)
    public Result checkUpperResult(@PathVariable("examId")String examId){
        return studentExamService.checkUpperResult(examId);
    }

    @Log("学生端:回显考试时的临时数据")
    @RequestMapping(value = "/echoTempAnswer/{id}",method = RequestMethod.GET)
    public Result echoTempAnswer(@PathVariable("id")String id){
        return studentExamService.echoTempAnswer(id);
    }

    @Log("学生端:学生主动交卷或强制交卷")
    @RequestMapping(value = "/saveStudentExam",method = RequestMethod.POST)
    public Result saveStudentExam(@RequestBody Map<String,Object> map){
        return studentExamService.saveStudentExam(map);
    }

    @Log("学生端：学生查看试卷:  如果当前学生的score中的status不是2, 试卷状态不是为6,则不允许")
    @RequestMapping(value = "/getShowExamStatus/{id}",method = RequestMethod.GET)
    public Result getShowExamStatus(@PathVariable("id") String id){
        return studentExamService.getShowExamStatus(id);
    }

    @Log("学生端：试卷讲解时,学生数据的回显")
    @RequestMapping(value = "/goBackStudentExamData",method = RequestMethod.POST)
    public Result goBackStudentExamData(@RequestBody Exam exam){
        return studentExamService.goBackStudentExamData(exam);
    }

    @Log("学生端：学生补考:  查看当前考试是否是补考状态或 学生试卷是否是0")
    @RequestMapping(value = "/getExamTypeAndStudentScore/{id}",method = RequestMethod.GET)
    public Result getExamTypeAndStudentScore(@PathVariable("id") String id){
        return studentExamService.getExamTypeAndStudentScore(id);
    }

    // 学生补考: score status 从0修改为1
    @RequestMapping(value = "/updateScoreStatus/{id}",method = RequestMethod.GET)
    public Result updateScoreStatus(@PathVariable("id") String id){
        return studentExamService.updateScoreStatus(id);
    }


}
